package com.wangchao.administrator.zenmechi.ui.loginactivity;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by cbb on 2016/10/18.
 * Email: 1023151857@qq.com
 */
public class LoginModle implements LoginContract.Model {
    private  boolean flag=false;
    private String passWord;
    //查询数据
    @Override
    public void query(final String id, Subscriber<String> pwd) {

        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {

                //查找Person表里面id为6b6c11c537的数据
                BmobQuery<Person> query = new BmobQuery<Person>();
                query.addWhereEqualTo("name", id);
                //执行查询方法
                query.findObjects(new FindListener<Person>() {
                    @Override
                    public void done(List<Person> object, BmobException e) {
                        if(e==null){
                           // Log.e("bmob","查询成功");
                           passWord= object.get(0).getAddress();
                        }else{
                          //  Log.i("bmob","失败："+e.getMessage()+","+e.getErrorCode());
                        }
                    }
                });
                subscriber.onNext(passWord);
            }
        }).subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(pwd);

    }
}
